package tech.aistar.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.aistar.pojo.Product;
import tech.aistar.pojo.Result;
import tech.aistar.service.ProductService;

import java.util.List;

@RestController
@RequestMapping("product")
public class ProductController {
	@Autowired
	private ProductService productService;
	
	@GetMapping("{pageNum}/{pageSize}")
	public Result index(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize) {
		PageInfo<Product> pageInfo = productService.page(pageNum, pageSize);
		return Result.success(pageInfo);
	}
	
	
	@GetMapping("{likeKey}/{pageNum}/{pageSize}")
	public Result productNameLikekey(
			@PathVariable("likeKey") String likeKey
			, @PathVariable("pageNum") Integer pageNum
			, @PathVariable("pageSize") Integer pageSize) {
		
		PageInfo<Product> pageInfo = productService.productNameLike("%" + likeKey + "%",pageNum, pageSize);
		return Result.success(pageInfo);
	}
	
	
}
